﻿using System;
using System.IO;
using Example.Application.Contracts;
using Example.Application.Extensions;
using Example.Infrastructure;
using Microsoft.Extensions.Configuration;
using Sean.Utility.Contracts;
using Sean.Utility.Extensions;
using Sean.Utility.Impls.Log;

namespace Example.TestApp;

class Program
{
    static void Main(string[] args)
    {
        Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);// 设置当前工作目录：@".\"

        #region Logger配置
        SimpleLocalLoggerBase.DateTimeFormat = time => time.ToLongDateTime();
        SimpleLocalLoggerBase.DefaultLoggerOptions = new SimpleLocalLoggerOptions
        {
            LogToConsole = true,
            LogToLocalFile = false
        };
        #endregion

        #region 依赖注入
        DIManager.Register(container =>
        {
            // Configuration注入
            var configurationBuilder = new ConfigurationBuilder()
                .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                .AddJsonFile("appsettings.json", true, true)
                .AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();
            container.RegisterType<IConfiguration>(configuration);

            container.AddApplicationDI();
        });
        #endregion

        ILogger logger = DIManager.Resolve<ILogger<Program>>();
        logger.LogInfo("这是一条测试日志");

        IConfiguration configuration = DIManager.Resolve<IConfiguration>();
        var loggerSection = configuration.GetSection("SimpleLocalLoggerOptions");
        var logToConsole = loggerSection.GetValue<bool>(nameof(SimpleLocalLoggerOptions.LogToConsole));
        var logToLocalFile = loggerSection.GetValue<bool>(nameof(SimpleLocalLoggerOptions.LogToLocalFile));

        ITestService testService = DIManager.Resolve<ITestService>();
        testService.Hello("靓仔！！！");

        Console.ReadLine();
    }
}